home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / WILD.ASM < prev    next >
Assembly Source File  |  1988-03-16  |  38KB  |  853 lines

  1. ; WILD Public Domain 1988 by Charles Lazo III, v1.0
  2.  
  3. ; WILD.ASM    This program is used to run any other program (or DOS command)
  4. ;        by expanding program wild card parameters given on the command
  5. ;        line.  E.g., WILD PROG *.* would run a program, say PROG.EXE,
  6. ;        multiple times and supply it each time with a file from the
  7. ;        current directory matching *.* (i.e., every file in the current
  8. ;        directory would be supplied to PROG for execution).
  9.  
  10. rt        equ    0dh
  11. lf        equ    0ah
  12. of        equ    offset
  13. bptr        equ    byte ptr
  14. wp        equ    word ptr
  15.  
  16. code        segment
  17.         assume    cs:code, ds:code
  18.  
  19.         org    2ch
  20. env_seg        dw    ?        ; pointer to segment of our environment
  21.  
  22.         org    100h
  23. begin:        jmp    start
  24.  
  25. ;-------------------------------------------------------------------------------
  26. ; The wild card specification is placed here at the bottom of our stack to avoid
  27. ; having to specially set aside space for it.  It is used by the find_first
  28. ; routine to find the first file in the current directory meeting the wild card
  29. ; specification using the DOS Find First function.
  30. ;-------------------------------------------------------------------------------
  31. wild_spec    db    16 dup('STACK   ')    ; 128 bytes for stack
  32. our_stack    label    word
  33.  
  34. ss_save        dw    ?    ; place to store ss:sp
  35. sp_save        dw    ?
  36.  
  37. memory_used    dw    ?    ; keep track of memory paragraphs used
  38. env_size    dw    ?    ; number of bytes in the environment stored here
  39. cspc_addr    label    dword
  40.         dw    2 dup(?); store address of comspec variable here
  41. left_blank    dw    ?    ; stores pointer to start of wild card spec
  42. right_blank    dw    ?    ; stores pointer to end of wild card spec
  43. copy_size    dw    ?    ; stores size of command on command line (WILD)
  44. buffer_ptr    dw    0    ; pointer to buffer for list of filenames
  45.  
  46. switches    db    0        ; record presence of QUERY & NOEXT here
  47. file_attr    dw    0        ; store file attributes for file find
  48.  
  49. cmd_line    db    128 dup(0)    ; save original command line here
  50.  
  51. cmdl        db    ?,'/c',128 dup(?)    ; command line for EXEC
  52.  
  53. ;-------------------------------------------------------------------------------
  54. ; The parameter table to be passed to the DOS EXEC function:
  55. ;-------------------------------------------------------------------------------
  56. params        dw    ?    ; segment of environment block stored here
  57.         dw    of cmdl    ; offset of command line for program EXECed
  58.         dw    ?    ; segment of command line for program EXECed
  59.         dw    55h    ; offset of first FCB
  60.         dw    ?    ; segment of first FCB
  61.         dw    65h    ; offset of second FCB
  62.         dw    ?    ; segment of second FCB
  63.  
  64. ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  65. ; The following routines (up to the label buffer:) operate under the assumption
  66. ; that both ds and es are set to the code segment of WILD.
  67. ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  68.  
  69. ;-------------------------------------------------------------------------------
  70. ; When the WILD environment variable has NOEXT in its assignment string, then
  71. ; filename extensions are ignored (not supplied) when commands are passed to
  72. ; the DOS EXEC function.  This routine will remove any extension from the file-
  73. ; name in the DTA placed there by the DOS Find First and Continue File Search
  74. ; functions if NOEXT was found in the WILD environment variable.  The extension
  75. ; is removed by replacing the period separating the main part from the extension
  76. ; with a null.  Note that if a period is the only part of the filename, then it
  77. ; must be the dot representing the current directory so it is not removed.
  78. ;-------------------------------------------------------------------------------
  79.  
  80. remove_ext?    proc    near        ; removes any extension from filename
  81.         test    switches,noe    ; is WILD NOEXT env variable set?
  82.         jz    no_remove    ; no, don't remove extension
  83.         xor    al,al        ; find null terminating filename
  84.         mov    cx,14        ; max number of characters in ASCIIZ+1
  85.         cld            ; (for maintenance and documentation)
  86.         repne    scasb        ; search for null
  87.         sub    di,9eh        ; compute number of filename characters
  88.         mov    cx,di        ; and place it in cx for next search
  89.         mov    al,'.'        ; search for period prior to extension
  90.         mov    di,9eh        ; offset of filename in DTA
  91.         repne    scasb        ; search for period
  92.         jcxz    no_remove    ; can't remove extension if not there
  93.         cmp    di,9fh        ; if the period was the ONLY character,
  94.         jz    no_remove    ;   then it is the current directory
  95.         mov    bptr [di-1],0    ; set it to null to remove the extension
  96. no_remove:    ret
  97. remove_ext?    endp
  98.  
  99. ;-------------------------------------------------------------------------------
  100. ; find_size computes the length of a filename in the DTA placed there by the DOS
  101. ; find first and continue file search functions.  The length of the filename is
  102. ; returned in cx (the null character at the end of the ASCIIZ string is included
  103. ; in the count).  This routine is similar to file_size, qv.
  104. ;-------------------------------------------------------------------------------
  105.  
  106. find_size    proc    near        ; find size of filename (returned in cx)
  107.         call    remove_ext?    ; eliminate filename extension?
  108.         xor    al,al        ; find null at end of ASCIIZ filename
  109.         mov    di,9eh        ; offset of filename in DTA
  110.         mov    cx,14        ; max number of characters in ASCIIZ+1
  111.         cld            ; (for maintenance and documentation)
  112.         repne    scasb        ; search for null in ASCIIZ filename
  113.         sub    di,9eh        ; compute number of filename characters
  114.         mov    cx,di        ; return value in cx
  115.         ret
  116. find_size    endp
  117.  
  118. ;-------------------------------------------------------------------------------
  119. ; In this routine we check to see if there is enough memory presently allocated
  120. ; for the filename buffer to place another filename in the buffer.  First di is
  121. ; is set to the location in the buffer where the next filename will go.  If not
  122. ; enough memory has been allocated to allow the placement of another filename
  123. ; in the buffer, then more memory is allocated.  By using only the memory that
  124. ; is needed by the buffer (additional memory is allocated in blocks of 16 para-
  125. ; graphs or 256 bytes; an arbitrary value) the remaining memory can be used in
  126. ; the EXEC call.
  127. ;-------------------------------------------------------------------------------
  128.  
  129. set_di        proc    near        ; sets di to point to next available
  130.         mov    di,buffer_ptr    ;   location in filename buffer
  131.         push    cx        ; save filename size
  132.         or    di,di        ; is it zero (uninitialized)?
  133.         jz    init_di        ; yes, point it to start of buffer
  134.         mov    bx,di        ; use bx to find paragraphs used now
  135.         add    bx,0fh        ; round up to next paragraph
  136.         shr    bx,1        ; determine paragraph count
  137.         shr    bx,1
  138.         shr    bx,1
  139.         shr    bx,1
  140.         inc    bx        ; reserve one more than used
  141.         mov    ax,memory_used    ; memory paragraphs presently allocated
  142.         cmp    bx,ax        ; is memory to be used > allocated?
  143.         ja    get_more    ; yes, get more memory
  144. di_set:        pop    cx        ; restore filename size
  145.         ret
  146. get_more:    add    ax,16        ; ask for 256 more bytes (16 paragraphs)
  147.         mov    bx,ax        ; request sent in bx
  148.         mov    dx,ax        ; store in dx to assure request granted
  149.         mov    ah,4ah        ; DOS memory modify function (es is ok)
  150.         int    21h        ; ask DOS for it
  151.         cmp    bx,dx        ; DOS give what we wanted?
  152.         mov    dx,of mem_need    ; address error message in case not
  153.         jz    got_it        ; got requested memory
  154.         jmp    error_exit    ; nope, DOS don't have it, terminate
  155. init_di:    mov    di,of buffer
  156.         jmp    short di_set    ; exit with di at start of buffer
  157. got_it:        mov    memory_used,bx    ; update memory allocated
  158.         pop    cx        ; restore filename size
  159.         ret
  160. set_di        endp
  161.  
  162. ;-------------------------------------------------------------------------------
  163. ; With this call we copy the filename in the DTA (placed there by DOS Find First
  164. ; and Continue File Search functions) into the filename buffer.
  165. ;-------------------------------------------------------------------------------
  166.  
  167. store_filename    proc    near        ; store filename of file find in buffer
  168.         call    find_size    ; find size of filename in DTA (to cx)
  169.         call    set_di        ; set di to next location in buffer
  170.         mov    si,9eh        ; offset of filename in DTA
  171.         cld            ; (for maintenance and documentation)
  172.         rep    movsb        ; move ASCIIZ filename to buffer
  173.         mov    buffer_ptr,di    ; update buffer pointer
  174.         ret
  175. store_filename    endp
  176.  
  177. ;-------------------------------------------------------------------------------
  178. ; This one is similar t